clear			all
set 			more off
cd 				"~/Dropbox/Indonesia Migration/" // Specify your root directory here
use				"Data/Census_1976.dta", clear		
foreach			t in 1980 1985 1990 1995 2000 2005 2010 {
append			using "Data/Census_`t'.dta"
}

/*******************************************************************************
OVERALL (except IPC 2000 & SUPAS 2005)
*******************************************************************************/
foreach 		i in 1976 1980 1985 1990 1995 2010 {
preserve
keep 			if year == `i'
gen 			male = sex==1
gen 			age_years = age if age != 999
gen 			education_level = edattain if inrange(edattain,1,4)
gen 			single =  marst==1
gen 			lives_alone = hhtype == 1
gen				LFP = 1 if inrange(empstat,1,2)
replace			LFP = 0 if missing(LFP)	& !missing(empstat) 
gen				emp = 1 if inrange(classwk,1,4)
replace			emp = 0 if missing(emp)	& !missing(classwk)
gen				wage = 1 if classwk == 2
replace			wage = 0 if missing(wage) & !missing(classwk)
gen				SE = 1 if classwk == 1
replace			SE = 0 if missing(SE) & !missing(classwk)
gen				unpaid = 1 if classwk == 3
replace			unpaid = 0 if missing(unpaid) & !missing(classwk)
gen 			urban_dist = urban == 2

label 			var male "Proportion male"
label 			var age_years "Average age"
label 			var education_level "Level of education"
label 			var single "Proportion never married"
label 			var lives_alone "One-member househoold"
label 			var LFP "Labour force participation"
label 			var emp "Employed"
label 			var wage "Wage employment"
label 			var SE "Self-employment"
label 			var unpaid "Unpaid work"
label 			var urban_dist "Lives in urban area"

asdoc tabstat 	male age_years education_level single lives_alone LFP emp wage ///
				SE unpaid urban_dist if migstat == 0, dec(3) label stat(N mean sd) ///
				save(Summary_Stats`i'.doc) replace
asdoc tabstat 	male age_years education_level single lives_alone LFP emp wage ///
				SE unpaid urban_dist if migstat == 1, dec(3) label stat(N mean sd) ///
				save(Summary_Stats`i'.doc) append
asdoc tabstat 	male age_years education_level single lives_alone LFP emp wage ///
				SE unpaid urban_dist if migstat == 2, dec(3) label stat(N mean sd) ///
				save(Summary_Stats`i'.doc) append


asdoc 			ttest male if inlist(migstat,0,1), by(migstat) dec(3) ///
				save(Summary_Stats`i'.doc) append
				 
foreach			var in age_years education_level single lives_alone LFP emp wage ///
				SE unpaid urban_dist {
asdoc 			ttest `var'  if inlist(migstat,0,1), by(migstat) dec(3) stars ///
				save(Summary_Stats`i'.doc) rowappend
}


asdoc 			ttest male if inlist(migstat,1,2), by(migstat) dec(3) ///
				save(Summary_Stats`i'.doc) append
				 
foreach			var in age_years education_level single lives_alone LFP emp wage ///
				SE unpaid urban_dist {
asdoc 			ttest `var'  if inlist(migstat,1,2), by(migstat) dec(3) stars ///
				save(Summary_Stats`i'.doc) rowappend
}

asdoc 			ttest male if inlist(migstat,0,2), by(migstat) dec(3) ///
				save(Summary_Stats`i'.doc) append
				 
foreach			var in age_years education_level single lives_alone LFP emp wage ///
				SE unpaid urban_dist {
asdoc 			ttest `var'  if inlist(migstat,0,2), by(migstat) dec(3) stars ///
				save(Summary_Stats`i'.doc) rowappend
}
restore
}

/*******************************************************************************
IPC 2000 & SUPAS 2005 (LFP missing)
*******************************************************************************/
foreach 		i in 2000 2005 {
preserve
keep 			if year == `i'
gen 			male = sex==1
gen 			age_years = age if age != 999
gen 			education_level = edattain if inrange(edattain,1,4)
gen 			single =  marst==1
gen 			lives_alone = hhtype == 1
gen				emp = 1 if inrange(classwk,1,4)
replace			emp = 0 if missing(emp)	& !missing(classwk)
gen				wage = 1 if classwk == 2
replace			wage = 0 if missing(wage) & !missing(classwk)
gen				SE = 1 if classwk == 1
replace			SE = 0 if missing(SE) & !missing(classwk)
gen				unpaid = 1 if classwk == 3
replace			unpaid = 0 if missing(unpaid) & !missing(classwk)
gen 			urban_dist = urban == 2

label 			var male "Proportion male"
label 			var age_years "Average age"
label 			var education_level "Level of education"
label 			var single "Proportion never married"
label 			var lives_alone "One-member househoold"
label 			var emp "Employed"
label 			var wage "Wage employment"
label 			var SE "Self-employment"
label 			var unpaid "Unpaid work"
label 			var urban_dist "Lives in urban area"

asdoc tabstat 	male age_years education_level single lives_alone emp wage ///
				SE unpaid urban_dist if migstat == 0, dec(3) label stat(N mean sd) ///
				save(Summary_Stats`i'.doc) replace
asdoc tabstat 	male age_years education_level single lives_alone emp wage ///
				SE unpaid urban_dist if migstat == 1, dec(3) label stat(N mean sd) ///
				save(Summary_Stats`i'.doc) append
asdoc tabstat 	male age_years education_level single lives_alone emp wage ///
				SE unpaid urban_dist if migstat == 2, dec(3) label stat(N mean sd) ///
				save(Summary_Stats`i'.doc) append


asdoc 			ttest male if inlist(migstat,0,1), by(migstat) dec(2) ///
				save(Summary_Stats`i'.doc) append
				 
foreach			var in age_years education_level single lives_alone emp wage ///
				SE unpaid urban_dist {
asdoc 			ttest `var'  if inlist(migstat,0,1), by(migstat) dec(3) stars ///
				save(Summary_Stats`i'.doc) rowappend
}


asdoc 			ttest male if inlist(migstat,1,2), by(migstat) dec(3) ///
				save(Summary_Stats`i'.doc) append
				 
foreach			var in age_years education_level single lives_alone emp wage ///
				SE unpaid urban_dist {
asdoc 			ttest `var'  if inlist(migstat,1,2), by(migstat) dec(3) stars ///
				save(Summary_Stats`i'.doc) rowappend
}

asdoc 			ttest male if inlist(migstat,0,2), by(migstat) dec(3) ///
				save(Summary_Stats`i'.doc) append
				 
foreach			var in age_years education_level single lives_alone emp wage ///
				SE unpaid urban_dist {
asdoc 			ttest `var'  if inlist(migstat,0,2), by(migstat) dec(3) stars ///
				save(Summary_Stats`i'.doc) rowappend
}
restore
}











